import array.*;
import common.PrimeNumbers;
import kmp.Normal;
import node.AddTwoNumber;
import node.ListNode;
import org.junit.Test;
import sort.*;
import string.BinaryAdd;
import string.CommonPrefix;
import string.StringTest;

import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 算法测试
 */
public class AlgorithmsTest {


    @Test
    public void testFindDiagonalOrder(){
        int[][] a = {{1,2,3},{4,5,6},{7,8,9}};
        int[] diagonalOrder = new Diagonal().findDiagonalOrder(a);
        for(int i=0;i<diagonalOrder.length;i++){
            System.out.print(diagonalOrder[i]+" ");
        }
    }

    @Test
    public void testSpiralOrder2(){
        int[][] a = {{1,2,3},{4,5,6},{7,8,9}};
        System.out.println(new SpiralOrder().spiralOrder2(a));
    }


    @Test
    public void  testBubbleSort(){

        int[] nums = {1,5,9,6,3,8};

        new BubbleSort().bubble(nums);
        for(int i=0;i<nums.length;i++){
            System.out.print("nums: " + nums[i]+ "  ");
        }
    }

    @Test
    public void  testSelectSort(){

        int[] nums = {1,5,9,6,3,8};

        new SelectSort().sorting(nums);
        for(int i=0;i<nums.length;i++){
            System.out.print("nums: " + nums[i]+ "  ");
        }

    }

    @Test
    public void testInsertion(){
        int[] nums = {1,5,9,6,3,8};

        new InsertionSort().insertion(nums);
        for(int i=0;i<nums.length;i++){
            System.out.print("nums: " + nums[i]+ "  ");
        }

    }

    @Test
    public void testKMP(){
        String s = "abhjklomn";
        String t = "jkl";
        int result = new Normal().ViolentMatch(s, t);
        System.out.println(result);

        double a = 0.2;
        double b = 0.1;
        System.out.println(a+b);
    }

    /**
     * 0,1,0,3,12
     * 0,0,1
     * 0,1,0
     */
    @Test
    public void testMoveZero(){
        int[] nums = {0,1,0};
        MoveZero moveZero = new MoveZero();
        moveZero.moveZeroes2(nums);
        for (int num : nums) {
            System.out.println(num);
        }
    }

    @Test
    public void testBinaryAdd(){

        String s = "1111";
        String l = "1111";
        System.out.println(new BinaryAdd().addBinary1(s,l));
    }

    @Test
    public void  testCommonPrefix(){
        String[] strs = {"flower","flow","flight"};
        System.out.println(new CommonPrefix().longestCommonPrefix2(strs));
    }

    @Test
    public void testNodeTwoNumberAdd(){
        ListNode a = new ListNode(2);
        a.next = new ListNode(4);
        a.next.next = new ListNode(3);

        ListNode b = new ListNode(5);
        b.next = new ListNode(6);
        b.next.next = new ListNode(4);

        ListNode listNode = new AddTwoNumber().addTwoNumbers(a, b);
        System.out.println(listNode);

    }

    @Test
    public void testThreeNumberAdd(){
        int[] nums = {0,0,0,0};
        List<List<Integer>> lists = new ThreeNumerAdd().threeSum(nums);
        System.out.println(lists);
    }

    @Test
    public void testPrimeNumbers(){

        for(int a=0;a<12;a++){
            System.out.println(new PrimeNumbers().countPrimes(a));
        }

    }

    @Test
    public void run(){

        List<String> list = new ArrayList<>();
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("luluelue");

    }

    @Test
    public void mergeSortTest(){
        int[] arr = {1,8,2,7,3,6,4,5};
        MergeSort.sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    @Test
    public void quickSortTest(){
        int[] arr = {1,8,2,7,3,6,4,5};
        QuickSort.quickSort(arr);
        System.out.println(Arrays.toString(arr));
    }

}

